package com.asiainfo.order.controller;

import com.asiainfo.entity.order.Order;
import com.asiainfo.order.config.OrderProperties;
import com.asiainfo.order.feign.BaiduFeign;
import com.asiainfo.order.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RefreshScope
@RestController
@RequestMapping("/api/order")
public class OrderController {

    @Autowired
    OrderService orderService;

    //获取配置中心的配置

    @Value("${clickhouse.jdbc.url}")
    String url;
    @Value("${clickhouse.jdbc.username}")
    String username;
    @Value("${clickhouse.jdbc.password}")
    String password;
    @Value("${clickhouse.jdbc.poolsize}")
    Integer poolszie;

    @Value("${clickhouse.jdbc.timeout}")
    Integer timeout;

    @Autowired
    OrderProperties orderProperties;
    @Autowired
    BaiduFeign baiduFeign;

    @GetMapping("/baidu")
    public String getBaidu(){
        return baiduFeign.getBaiduInfo();
    }

    //返回订单详情
    @GetMapping("/info")
    public Order getOrderInfo(@RequestParam("userId") Long userId, @RequestParam("productId") Long productId){
        Order order=orderService.createOrder(userId,productId);
        return order;
    }

    @GetMapping("/config")
    public String get(){
        System.out.println(
                "url:"+url+"\n"+
                "usernmae:"+username+"\n"+
                "password:"+password+"\n"+
                "poolsize:"+poolszie+"\n"+
                "timeout:"+timeout+"\n"
        );
        return   "url:"+url+"\n"+
                "usernmae:"+username+"\n"+
                "password:"+password+"\n"+
                "poolsize:"+poolszie+"\n"+
                "timeout:"+timeout+"\n";
    }


    @GetMapping("/config2")
    public String conf2(){
        return orderProperties.toString();
    }
}
